package com.office.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

/**
 * 向量数据库配置
 * @author 数字牧马人
 */

@Configuration
public class PostgresConfig {

    @Value("${spring.datasource.druid.postgres.url}")
    private String url;

    @Value("${spring.datasource.druid.postgres.username}")
    private String username;

    @Value("${spring.datasource.druid.postgres.password}")
    private String password;

    @Value("${spring.datasource.druid.postgres.driver-class-name}")
    private String driverClassName;

    @Bean(name = "postgresDataSource")
    public DataSource postgresDataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }

    @Bean(name = "postgresJdbcTemplate")
    public JdbcTemplate postgresJdbcTemplate(@Qualifier("postgresDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}
